package yf.mall.controller.api;

import com.github.pagehelper.PageHelper;
import com.yf.annotation.LoginUserId;
import com.yf.response.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yf.mall.entity.CommentEntity;
import yf.mall.service.CommentService;
import yf.mall.service.UserService;

import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class ApiCommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 评论
     * @param userId
     * @param goodsId
     * @param itemId
     * @param content
     * @return
     */
    @RequestMapping("/comment")
    public R comment(@LoginUserId Long userId,Long goodsId,Long itemId,String content){
        commentService.comment(userId,goodsId,itemId,content);
        return R.ok();
    }

    @RequestMapping("/getComments")
    public R getComments(Long goodsId,Integer page,Integer limit){
        PageHelper.startPage(page,limit);
        List<CommentEntity> entities = commentService.findByGoodsId(goodsId);
        return R.ok(entities);
    }
}
